package agent;

import common.Piece;
import common.DominoState;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;

public class AgentState extends DominoState {

    /**
     * List of the agent's pieces.
     */
    protected LinkedList<Piece> agentPieces;
    //peçasPossiveisDoAdversario
    public LinkedList<Piece> opponentPossiblePieces;
    protected Player lastPlayer = Player.NONE;

    public AgentState() {
        super();
        opponentPossiblePieces = new LinkedList<>();
        agentPieces = new LinkedList<>();
    }

    public AgentState(LinkedList<Piece> agentPieces, LinkedList<Piece> playedPieces) {
        super();
        if(playedPieces != null)
            this.playedPieces = playedPieces;
        this.agentPieces = new LinkedList<>();
        for(Piece p : agentPieces)
            this.agentPieces.add(p);
        opponentPossiblePieces = new LinkedList<>();
        for (Piece piece : allPieces) {
            if (!agentPieces.contains(piece)) {
                opponentPossiblePieces.add(piece);
            }
        }
    }
    
    public AgentState(DominoState ds){
        super(ds);
        opponentPossiblePieces = new LinkedList<>();
        agentPieces = new LinkedList<>();
    }
    
    public void recalcOpponentPossiblePiecesBasedOnPlayerSkip(byte leftValue, byte rightValue){
//        System.out.println("skip bounds("+leftValue+","+rightValue+")");
        for (Iterator<Piece> it = opponentPossiblePieces.iterator(); it.hasNext();) {
            Piece p = it.next();
            if(p.getValue1() == leftValue || p.getValue1() == rightValue
             ||p.getValue2() == leftValue || p.getValue2() == rightValue){
//                System.out.println("skipping piece("+p.getValue1()+","+p.getValue2()+")");
                it.remove();
            }
        }
    }
    
}
